<?php

class usuarioController extends Zend_Controller_Action {

    public function init() {
        if (!Zend_Auth::getInstance()->hasIdentity()) {
            return $this->_helper->redirector->goToRoute(array('controller' => 'index'), null, true);
        }
    }

    public function indexAction() {
        $usuario = Zend_Auth::getInstance()->getIdentity();
        $this->view->usuario = $usuario;
        $this->_helper->layout->disableLayout();
        // PARA REMOVER LAYOUT
    }
    
     public function calendarioAction() {
        $usuario = Zend_Auth::getInstance()->getIdentity();
        $this->view->usuario = $usuario;
        $this->_helper->layout->disableLayout();
        // PARA REMOVER LAYOUT
     }
     
     public function duvidasAction() {
        $usuario = Zend_Auth::getInstance()->getIdentity();
        $this->view->usuario = $usuario;
        $this->_helper->layout->disableLayout();
        // PARA REMOVER LAYOUT
        
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->view->messages = $this->_flashMessenger->getMessages();
        $form = new Application_Form_duvidas();
        $this->view->form = $form;
        
        //Verifica se existem dados de POST 
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost();
//Formulário corretamente preenchido? 
            if ($form->isValid($data)) {
                $email = $form->getValue('email');
                $assunto = $form->getValue('assunto');
                $mensagem = $form->getValue('mensagem');
                $duvidas = new Application_Model_DbTable_duvidas();
                $duvidas->addDuvida($email, $assunto, $mensagem);
                $this->_helper->redirector->goToRoute(array('controller' => 'usuario','action' => 'duvidas', 'module' => 'default'), null, true);
            
            } else {
                $form->populate($data);
            }
            
        }
     }

}

